package com.itheima.reggie.controller;

import com.itheima.reggie.common.R;
import com.itheima.reggie.entity.Orders;
import com.itheima.reggie.entity.Page;
import com.itheima.reggie.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/order")
@Slf4j
public class OrderController {
    @Autowired(required = false)
    private OrderService orderService;

    /*下单*/
    @PostMapping("/submit")
    public R<String> submit(@RequestBody Orders orders, HttpSession session){
        //获得登入者信息
        Long userId = (Long) session.getAttribute("user");
        orderService.submit(orders,userId);
        return R.success("下单成功");
    }
    /*订单分页查询*/
    @GetMapping("/page")
    public R<Page<Orders>> Page(Integer page,Integer pageSize,Long number,String beginTime,String endTime){
        Page<Orders> pageResult = orderService.page(page,pageSize,number,beginTime,endTime);
        return R.success(pageResult);
    }
    /*历史订单分页查询*/
    @GetMapping("/userPage")
    public R<Page<Orders>> userPage(Integer page,Integer pageSize,Long number){
        Page<Orders> pageResult= orderService.userPage(page,pageSize,number);
        return R.success(pageResult);
    }
}
